<?php
namespace app\feelym\controller;

use app\common\controller\AdminBase;
use org\Http;
use org\PclZip;
use think\Db;

/**
 * 后台首页
 * Class Index
 * @package app\feelym\controller
 */
class Index extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();

    }
    public function undefined()
    {
        return $this->fetch();
    }

    /**
     * 首页
     * @return mixed
     */
    public function adminindex()
    {

        $baseUrl = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'])) . '/';

        $root    = 'http://' . $_SERVER['HTTP_HOST'] . $baseUrl;
        $version = Db::query('SELECT VERSION() AS ver');
        $config  = [
            'url'             => $_SERVER['HTTP_HOST'],
            'document_root'   => $_SERVER['DOCUMENT_ROOT'],
            'server_os'       => PHP_OS,
            'server_port'     => $_SERVER['SERVER_PORT'],
            'server_soft'     => $_SERVER['SERVER_SOFTWARE'],
            'php_version'     => PHP_VERSION,
            'mysql_version'   => $version[0]['ver'],
            'max_upload_size' => ini_get('upload_max_filesize'),
        ];
        $this->assign('root', $root);
        return $this->fetch('adminindex', ['config' => $config]);
    }
    public function home()
    {
        $artCount=Db::name('article')->count();
        $artWaitCheck=Db::name('article')->where('open',0)->count();
        $forumCount=Db::name('forum')->count();
        $forumWaitCheck=Db::name('forum')->where('open',0)->count();
        $userCount=Db::name('user')->count();
        $userRegToday=Db::name('user')->where('regtime>'.strtotime(date('Y-m-d')))->count();
        $this->assign('tongji', array('artCount'=>$artCount,
        'artWaitCheck'=>$artWaitCheck,'forumCount'=>$forumCount,'forumWaitCheck'=>$forumWaitCheck,
    'userCount'=>$userCount,'userRegToday'=>$userRegToday
    ));
    $admin_more = Db::name('system')->field('value')->where('name', 'admin_more')->find();
    $admin_more = unserialize($admin_more['value']);
    $this->assign('gonggao', $admin_more['gonggao']);
    return $this->fetch();
    }

    function updatesql($sqldir) {
        $db_config = array();
        $config=new \think\Config();
        $db_config['prefix'] = $config::get('database.prefix');
        $sqldata =file_get_contents($sqldir);
        $sql_array=preg_split("/;[\r\n]+/", str_replace('ls_',$db_config['prefix'],$sqldata));
        foreach ($sql_array as $k => $v) {
            if (!empty($v)) {
                Db::query($v);
            }
        }
    }

}
